package controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;


import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;

import static java.time.DayOfWeek.MONDAY;
import static java.time.DayOfWeek.SUNDAY;
import static java.time.temporal.TemporalAdjusters.nextOrSame;
import static java.time.temporal.TemporalAdjusters.previousOrSame;

public class Dayofweek {
	//gets the date for this weeks Monday
	public static LocalDate getFirstDayOfWeek() {
		LocalDate today = LocalDate.now();

		LocalDate monday = today.with(previousOrSame(MONDAY));
		
		return monday;

	}
	//gets the date for this weeks Sunday
	public static LocalDate getLastDayOfWeek() {
		LocalDate today = LocalDate.now();

		LocalDate sunday = today.with(nextOrSame(SUNDAY));

		return sunday;

		
	}
	public static LocalDateTime getFirstDayTimeOfWeek() {
		LocalDateTime today = LocalDateTime.now();

		LocalDateTime monday = today.with(previousOrSame(MONDAY));
		
		return monday;

	}
	public static LocalDateTime getLastDayTimeOfWeek() {
		LocalDateTime today = LocalDateTime.now();
		
		LocalDateTime sunday = today.with(nextOrSame(SUNDAY));

		return sunday;

		
	}
	public static String getLastDayOfMonth(int month, int year){

		    Calendar calendar = Calendar.getInstance();
		    // passing month-1 because 0-->jan, 1-->feb... 11-->dec
		    calendar.set(year, month - 1, 1);
		    calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
		    Date date = calendar.getTime();
		    DateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/YYYY");
		    return DATE_FORMAT.format(date);
		}
		
}
